# -*- coding: utf-8 -*-

import base64
import gzip

class Func(object):
    """Func-通用函数类"""

    @classmethod
    def encode_json_str(cls, s):
        gdt = gzip.compress(s.encode('utf-8'))
        sts = base64.b64encode(gdt).decode('ASCii')
        sts = sts.replace("+", "-").replace("/", "_")
        return sts

    @classmethod
    def decode_json_str(cls, s):
        s = s.replace("-", "+").replace("_", "/")
        dat = base64.b64decode(s.encode('ASCii'))
        sts = gzip.decompress(dat).decode('utf-8')
        return sts

    @classmethod
    def encode_json_bin(cls, b):
        gdt = gzip.compress(b)
        sts = base64.b64encode(gdt).decode('ASCii')
        sts = sts.replace("+", "-").replace("/", "_")
        return sts

    @classmethod
    def decode_json_bin(cls, s):
        s = s.replace("-", "+").replace("_", "/")
        data = base64.b64decode(s)
        b = gzip.decompress(data)
        return b
